/*
 * HD44780.h
 *
 *	  Modified: Aug 02, 2009 Orlando Arias
 *	  			Added command structure.
 *    Modified: Aug 01, 2009 Orlando Arias
 *    			Changed API to include lcd_ prefixes
 *	  Modified: Jul 21, 2009 Rugged Circuits LLC
 *				Modified to use pointers to LCD structure
 *  Created on: Jul 20, 2009
 *      Author: Orlando Arias
 *     License: GPLv3
 *
 *   Simple library to control HD44780 based LCD screens.
 *   Copyright (C) 2009  Orlando Arias
 *
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef HD44780_H_
#define HD44780_H_

#include <inttypes.h>
#include "WProgram.h"

/*
 * The following enum defines the two possible bit modes
 * in the LCD screen.
 *
 * If only 4 data pins are used, then bitmode must be set to
 * BIT_MODE_4, otherwise, all data pins are used and bitmode
 * must be set to BIT_MODE_8.
 */
typedef enum _bmode {
	BIT_MODE_4	=4,
	BIT_MODE_8	=8
} bmode;

typedef enum _command {
	BLANK_DISPLAY		=0x08,
	CLEAR				=0x01,
	CURSOR_INVISIBLE	=0x0C,
	CURSOR_VISIBLE_BB	=0x0F,
	CURSOR_VISIBLE_UL	=0x0E,
	EM_DECREMENT_OFF	=0x04,
	EM_DECREMENT_ON		=0x05,
	EM_INCREMENT_OFF	=0x06,
	EM_INCREMENT_ON		=0x07,
	MOVE_HOME			=0x02,
	MOVE_LEFT			=0x10,
	MOVE_RIGHT			=0x14,
	RESTORE_DISPLAY		=0x0C,
	SCROLL_LEFT			=0x18,
	SCROLL_RIGHT		=0x1E,
	SET_POSITION		=0x80,
} command;

typedef struct _LCD {
	int datapin[8];
	int rs_pin;
	int rw_pin;
	int enable_pin;
	bmode bitmode;
} LCD;

/*
 * function prototypes
 */
void lcd_clear(LCD *l);
void lcd_home(LCD *l);
void lcd_init(LCD *l);
void lcd_sendCommand(LCD *l, command cmd);
void lcd_locate(LCD *l, int row, int col);
void lcd_writeChar(LCD *l, uint8_t ch);
void lcd_writeStr(LCD *l, const char chArray[]);

#endif /* HD44780_H_ */
